package com.dysm.spring.security.resource.controller;

import com.dysm.spring.security.resource.annotion.Anonymous;
import com.dysm.spring.security.resource.domain.tongcheng.req.TongChengSignReq;
import com.dysm.spring.security.resource.domain.tongcheng.resp.TongChengSignResp;
import com.dysm.spring.security.resource.service.TongChengService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class TongChengSignController {

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TongChengService tongChengService;

    @PostMapping(path = "/tongCheng/sign")
    @Anonymous
    public ResponseEntity<TongChengSignResp> sign(HttpServletRequest request, @RequestBody TongChengSignReq req) {
        LOG.info("request.getRequestURI：{},req:{}", request.getRequestURI(), req);
        return ResponseEntity.ok(tongChengService.sign(req, "test"));
    }

    @PostMapping(path = "/tongCheng/request")
    @Anonymous
    public ResponseEntity<String> request(HttpServletRequest request, @RequestBody TongChengSignReq req,
                                          @RequestParam("mapping") String mapping,
                                          @RequestParam(value = "env", required = false) String env) {
        LOG.info("request.getRequestURI：{},req:{}", request.getRequestURI(), req);
        return ResponseEntity.ok(tongChengService.request(req, mapping, env));
    }

}
